import requests
import json
import time
test_url = "https://www.airbnb.com/"
def get_proxies():
    proxies = []
    return requests.get('http://106.14.191.186:5010/get_all').json()

def insert(p):
    with open('proxies.txt', 'r+') as f:
        allp = f.readline()
        if len(allp)>0:
            allp = json.loads(allp)
        else:
            allp = []
        allp.append(p)
    if len(allp) > 100:
        allp = allp[-100:]
    with open('proxies.txt', 'w+') as f:
        f.write(json.dumps(allp))

def valiate():
    for proxy in get_proxies():
        proxies = {
            'http': proxy,
            'https': proxy
        }
        try:
            requests.get(test_url, timeout=3, proxies=proxies, verify=False)
            insert(proxy)
        except Exception as e:
            print(e)


def run_get_proxies():

    while True:
        valiate()
        time.sleep(60)

run_get_proxies()